import java.util.Scanner;

/**
 * @Title: n皇后问题
 * @Author 贾金博
 * @Package PACKAGE_NAME
 * @Date 2024/3/14 19:54
 * @description: 经典的题
 */
public class n皇后问题 {
    public static  Scanner sc = new Scanner(System.in);
    public static int n;
    public static char[][] a = new char[15][15];
    //检测列的
    public static boolean[]l = new boolean[15];
    //检测 / 的
    public static boolean[] zx = new boolean[15 + 100]; //斜1
    //检测 \ 的
    public static boolean[] fx = new boolean[15 + 100];
    //检测的行 就去用dfs里面的length去控制


    public static void main(String[] args) {
        n = sc.nextInt();
        //初始化
        for(int i = 1; i <= n; ++ i ) {
            for(int j = 1; j <= n; ++ j ) {
                a[i][j] = '.';
            }
        }
        dfs(1);

    }

    public static void dfs(int len) {
        if(len == n + 1) {
            for(int i = 1; i <= n; ++ i ) {
                for(int j = 1; j <= n; ++ j ) {
                    System.out.print(a[i][j]);
                    System.out.print(j != n ? " " : "");
                }
                System.out.println();
            }
            System.out.println();
            return;
        }

        //放在这一行的哪一个啊 美枚举一下看看
        for(int i = 1; i <= n; ++ i ) {
            if(!l[i] && !zx[i - len + 10] && !fx[i + len]) {
                a[len][i] = 'Q';
                l[i] = true;
                zx[i - len + 10] = true;
                fx[i + len] = true;
                dfs(len + 1);
                //记得回溯
                a[len][i] = '.';
                l[i] = false;
                zx[i - len + 10] = false;
                fx[i + len] = false;
            }
        }

    }
}
